package coalition.formation;

import java.util.HashMap;

import coalition.formation.externality.Externality;
import coalition.formation.partitions.PartitionDecorator;



public class ExternalityCache implements Externality{

	HashMap<String, float[]> externalities = new HashMap<String, float[]>();
	Externality proxiedExternality;
	
	public ExternalityCache(Externality proxiedExternality){
		this.proxiedExternality = proxiedExternality;
	}
	
	@Override
	public float[] getExternalities(int[] partition) {
		String partitionHash = PartitionDecorator.convertToHashString(partition);
		float[] result = externalities.get(partitionHash);
		if(result == null){
			result = proxiedExternality.getExternalities(partition);
			externalities.put(partitionHash, result);
		}
		return result;
	}

	@Override
	public int getSize() {
		return proxiedExternality.getSize();
	}

}
